unit uniRelRelacaoCheque;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, QuickRpt, QRCtrls, ExtCtrls, DB, ADODB, jpeg;

type
  TfrmRelRelacaoCheque = class(TForm)
    QR_Rel: TADOQuery;
    DS_Rel: TDataSource;
    qrpRel: TQuickRep;
    QRBand1: TQRBand;
    QRLabel1: TQRLabel;
    QRLabel2: TQRLabel;
    qrlPeriodo: TQRLabel;
    qrlDtInicio: TQRLabel;
    QRLabel4: TQRLabel;
    qrlDtFim: TQRLabel;
    qrbDetalhe: TQRBand;
    qrlBanco: TQRLabel;
    QRBand2: TQRBand;
    QRLabel14: TQRLabel;
    QRSysData2: TQRSysData;
    QRSysData1: TQRSysData;
    qrlUsuario: TQRDBText;
    lbl2: TQRLabel;
    lbl3: TQRLabel;
    QRLabel3: TQRLabel;
    QRLabel5: TQRLabel;
    QR_RelTemp: TADOQuery;
    qrImgCliente: TQRImage;
    QRGroup1: TQRGroup;
    qrlRepresentante: TQRLabel;
    QRLabel6: TQRLabel;
    qrlFaturaParcela: TQRLabel;
    qrlNrCheque: TQRLabel;
    qrlValor: TQRLabel;
    qrlDtCompensacao: TQRLabel;
    QRLabel7: TQRLabel;
    qrlStatus: TQRLabel;
    QRL1: TQRLabel;
    qrlCliente: TQRLabel;
    QRLabel9: TQRLabel;
    qrlTitularCheque: TQRLabel;
    QRBand3: TQRBand;
    QRBand4: TQRBand;
    qrlTotalRep: TQRLabel;
    QRLabel10: TQRLabel;
    qrlTotGeral: TQRLabel;
    QRLabel11: TQRLabel;
    procedure qrbDetalheBeforePrint(Sender: TQRCustomBand;
      var PrintBand: Boolean);
    procedure QRGroup1BeforePrint(Sender: TQRCustomBand;
      var PrintBand: Boolean);
    procedure qrpRelBeforePrint(Sender: TCustomQuickRep;
      var PrintReport: Boolean);
    procedure QRBand3BeforePrint(Sender: TQRCustomBand;
      var PrintBand: Boolean);
    procedure QRBand4BeforePrint(Sender: TQRCustomBand;
      var PrintBand: Boolean);
  private
    sChequeAnterior : String;
    cTotRep,
    cTotGeral : Currency;
  public
    { Public declarations }
  end;

var
  frmRelRelacaoCheque: TfrmRelRelacaoCheque;

implementation

uses uniFuncBD, UniFuncoes;

{$R *.dfm}

procedure TfrmRelRelacaoCheque.qrbDetalheBeforePrint(Sender: TQRCustomBand;
  var PrintBand: Boolean); 
begin

  if QR_Rel.FieldByName('status').AsString = '' then
    qrlStatus.Caption := 'Em Aberto'
  else
  if QR_Rel.FieldByName('status').AsString = 'C' then
    qrlStatus.Caption := 'Compensado'
  else
  if QR_Rel.FieldByName('status').AsString = 'D' then
    qrlStatus.Caption := 'Devolvido'
  else
  if QR_Rel.FieldByName('status').AsString = 'P' then
    qrlStatus.Caption := 'Pago';

  if sChequeAnterior = QR_Rel.FieldByName('NR_CHEQUE').AsString then
  begin
    qrlValor.Caption := '-';
  end
  else
  begin
    qrlValor.Caption := formatarValor(QR_Rel.FieldByName('valor').AsString);
    sChequeAnterior := QR_Rel.FieldByName('NR_CHEQUE').AsString;
    cTotRep := cTotRep + QR_Rel.FieldByName('valor').AsCurrency;
    cTotGeral := cTotGeral + QR_Rel.FieldByName('valor').AsCurrency;;
  end;

  qrlFaturaParcela.Caption := QR_Rel.FieldByName('DS_FATURA_PARCELA').AsString;
  qrlNrCheque.Caption := QR_Rel.FieldByName('NR_CHEQUE').AsString;
  qrlBanco.Caption := QR_Rel.FieldByName('DS_BANCO').AsString;
  qrlDtCompensacao.Caption := QR_Rel.FieldByName('DT_COMPENSACAO').AsString;
  qrlCliente.Caption := QR_Rel.FieldByName('FANTASIA').AsString;
  qrlTitularCheque.Caption := QR_Rel.FieldByName('DS_TITULAR_CHEQUE').AsString;
end;

procedure TfrmRelRelacaoCheque.QRGroup1BeforePrint(Sender: TQRCustomBand;
  var PrintBand: Boolean);
begin
  sChequeAnterior := '';;
  qrlRepresentante.Caption := QR_Rel.FieldByName('NOME').AsString;
  cTotRep := 0;
end;

procedure TfrmRelRelacaoCheque.qrpRelBeforePrint(Sender: TCustomQuickRep;
  var PrintReport: Boolean);
begin
  cTotRep := 0;
  cTotGeral := 0;
end;

procedure TfrmRelRelacaoCheque.QRBand3BeforePrint(Sender: TQRCustomBand;
  var PrintBand: Boolean);
begin
  qrlTotalRep.Caption := formatarValor(cTotRep);
end;

procedure TfrmRelRelacaoCheque.QRBand4BeforePrint(Sender: TQRCustomBand;
  var PrintBand: Boolean);
begin
  qrlTotGeral.Caption := formatarValor(cTotGeral);
end;

end.
